package com.ykdl.member.kid.gears;



import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;

import com.ykdl.member.constant.KidAction;
import com.ykdl.member.kid.R;
import com.ykdl.member.kid.beans.RefreshToCouponEvent;
import com.ykdl.member.kid.fragments.CouponFragment;
import com.ykdl.member.kid.fragments.HasUsedFragment;
import com.ykdl.member.kid.fragments.MyCouponHasUsedFragment;
import com.ykdl.member.kid.fragments.MyCouponNotUsedFragment;
import com.ykdl.member.kid.fragments.MyCouponOnLineHasUsedFragment;
import com.ykdl.member.kid.fragments.MyCouponOnLineNotUsedFragment;
import com.ykdl.member.kid.fragments.MyCouponOnLineOutOfDateFragment;
import com.ykdl.member.kid.fragments.MyCouponOutOfDateFragment;
import com.ykdl.member.kid.fragments.NotUsedFragment;
import com.ykdl.member.kid.fragments.OnlineCouponFragment;
import com.ykdl.member.kid.fragments.OutOfDateFragment;
import com.ykdl.member.kid.marketcard.CardInfoActivity;
import com.ykdl.member.kid.marketcard.StoreCouponActivity;
import com.ykdl.member.views.FocusTextView;

import de.greenrobot.event.EventBus;
/**
 * 展示fragment
 * @author jiafeiyu
 *
 */
public class ShowFragmentActivity extends BaseFragmentActivity {
	
	private static final int ON_LINE_COUPON = 1;//在线支付可用--门店
	private static final int UN_LINE_COUPON = 2;//到店支付可用--门店
	
	private static final int ON_LINE_MYCOUPON_NOT_USED = 3;//在线支付可用--我的优惠券--未使用
	private static final int ON_LINE_MYCOUPON_HAS_USED = 4;//在线支付可用--我的优惠券--已使用
	private static final int ON_LINE_MYCOUPON_OUT_OF_DATE = 5;//在线支付可用--我的优惠券--已过期
	
	private static final int UN_LINE_COUPON_NOT_USED = 6;//到店支付可用--我的优惠券--未使用
	private static final int UN_LINE_COUPON_HAS_USED = 7;//到店支付可用--我的优惠券--已使用
	private static final int UN_LINE_COUPON_OUT_OF_DATE = 8;//到店支付可用--我的优惠券--已过期
	
	private String store_id;
	private FocusTextView title;
	private int type;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_unline_coupon);
		
		initView();
	}

	private void initView() {
		title = (FocusTextView) findViewById(R.id.title);
		Intent intent = getIntent();
		type = intent.getIntExtra("type", 1);
		store_id = intent.getStringExtra("store_id");
		findViewById(R.id.left).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				
				finish();
			}
		});
		
		
		FragmentManager manager = getSupportFragmentManager();
		FragmentTransaction tranaction = manager.beginTransaction();
		Fragment fragment;
		switch (type) {
		
		case ON_LINE_COUPON:
			fragment = new OnlineCouponFragment(store_id);
			tranaction.add(R.id.content, fragment);
			title.setText("在线支付可用优惠券");
			break;
		case UN_LINE_COUPON:
			fragment = new CouponFragment(store_id);
			tranaction.add(R.id.content, fragment);
			title.setText("到店支付可用优惠券");
			break;

		case ON_LINE_MYCOUPON_HAS_USED:
			fragment = new MyCouponOnLineHasUsedFragment();
			tranaction.add(R.id.content, fragment);
			title.setText("在线支付已使用优惠券");
			break;
		case ON_LINE_MYCOUPON_NOT_USED:
			fragment = new MyCouponOnLineNotUsedFragment();
			tranaction.add(R.id.content, fragment);
			title.setText("在线支付未使用优惠券");
			break;
		case ON_LINE_MYCOUPON_OUT_OF_DATE:
			fragment = new MyCouponOnLineOutOfDateFragment();
			tranaction.add(R.id.content, fragment);
			title.setText("在线支付已过期优惠券");
			break;
		case UN_LINE_COUPON_HAS_USED:
			fragment = new HasUsedFragment();
			tranaction.add(R.id.content, fragment);
			title.setText("到店支付已使用优惠券");
			
			break;
		case UN_LINE_COUPON_NOT_USED:
			fragment = new NotUsedFragment();
			tranaction.add(R.id.content, fragment);
			title.setText("到店支付未使用优惠券");
			break;
		case UN_LINE_COUPON_OUT_OF_DATE:
			fragment = new OutOfDateFragment();
			tranaction.add(R.id.content, fragment);
			title.setText("到店支付已过期优惠券");
			break;
		
		default:
			break;
		}
		tranaction.commit();
		
		findViewById(R.id.right).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				//去门店详情
				Intent intent = new Intent(ShowFragmentActivity.this,CardInfoActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				intent.putExtra(KidAction.STORE_ID, store_id+"");
				intent.putExtra("from","true");
				startActivity(intent);
			}
		});
	
		
	}
	
}
